//
// Created by miaomiaole on 2023/6/5.
//

#ifndef CMAKECXX_CONTAINER_H
#define CMAKECXX_CONTAINER_H

#include <iostream>

void multiset_str();


void print_set();


void print_map();

void operator_set();


void operator_map();

// 支持排序字段
class RuntimeCmp {
public:
    enum cmp_mode {
        normal, reverse
    };

    RuntimeCmp(cmp_mode m = normal) : mode(m) {
        std::cout << "RuntimeCmp generate" << std::endl;
    }

    // 重载运算符 ()
    template<typename T>
    bool operator()(const T &t1, const T &t2) const {
        return mode == normal ? t1 < t2 : t2 < t1;
    }

    // 支持 {} 传参
    bool operator==(const RuntimeCmp &&rc) const {
        return mode == rc.mode;
    }

private:
    cmp_mode mode;

};


class RuntimeStrCmp {
public:
    enum cmp_mode {
        normal, nocase
    };
private:
    const cmp_mode mode;

    static bool nocase_compare(char c1, char c2) {
        return toupper(c1) < toupper(c2);
    }

public:
    RuntimeStrCmp(cmp_mode m = normal) : mode(m) {};

    bool operator()(const std::string &s1, const std::string &s2) const {
        if (mode == normal) {
            return s1 < s2;
        } else {
            return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), nocase_compare);
        }
    }
};


template<typename T>
class initializer {
public:
    using value_type = T;

    using reference = const T &;

    using const_reference = const T &;

    using size_type = size_t;

    using iterator = const T *;

    using const_iterator = const T *;

    initializer() noexcept;

    size_t size() const noexcept;

    const T *begin() const noexcept;

    const T *end() const noexcept;
};

template<typename T>
const T *begin(initializer<T> lst) noexcept {
    return lst.begin();
}

template<typename T>
const T *end(initializer<T> lst) noexcept {
    return lst.end();
}

void for_each_operation();


#endif //CMAKECXX_CONTAINER_H
